package com.zhuoyian.dl;

import com.zhuoyian.dl.control.ParallelDownload;
import com.zhuoyian.dl.control.SerialDownload;
import com.zhuoyian.dl.control.VideoDownload;
import com.zhuoyian.dl.listener.DownloadListener;
import com.zhuoyian.dl.manager.DownloadManager;
import com.zhuoyian.dl.service.DownloadPresent;
import com.zhuoyian.dl.util.DownloadParameter;

public class Download {


	private Download() {
		super();
	}

	/**
	 * Ĭ���������� ,��������
	 * 
	 * @param context
	 * @param url
	 * @param DLType
	 */
	public static int serialDlFile( String url, int DLType) {
		return serialDl( new DownloadParameter(url, DLType, false), null, null,
				false);

	}

	/**
	 * Ĭ���������� ,��������
	 * 
	 * @param context
	 * @param url
	 * @param DLType
	 */
	public static int serialDlFile( String url, int DLType,
			DownloadListener downloadListener) {
		return serialDl( new DownloadParameter(url, DLType, false), null, downloadListener,
				false);
	}

	/**
	 * 
	 * @param context
	 * @param url
	 * @param DLType
	 * @param obj
	 * @param downloadListener
	 * @return
	 */
	public static int serialDlFile( String url, int DLType,
			Object obj, DownloadListener downloadListener) {
		return serialDl( new DownloadParameter(url, DLType, false), obj, downloadListener,
				false);
	}

	public static int serialDlFile( String url, int DLType,
			boolean isNewFile, DownloadListener downloadListener) {
		return serialDl( new DownloadParameter(url, DLType, isNewFile), null,
				downloadListener, false);
	}

	/**
	 * Ĭ�϶ϵ����� ,��������
	 * 
	 * @param context
	 * @param url
	 * @param DLType
	 */
	public static int serialDlPointFile( String url,
			int DLType) {
		return serialDl( new DownloadParameter(url, DLType, false), null, null,
				true);
	}

	/**
	 * Ĭ�϶ϵ����� ,��������
	 * 
	 * @param context
	 * @param url
	 * @param DLType
	 */
	public static int serialDlPointFile( String url,
			int DLType, DownloadListener downloadListener) {
		return serialDl( new DownloadParameter(url, DLType, false), null, downloadListener,
				true);
	}

	/**
	 * 
	 * @param context
	 * @param url
	 * @param DLType
	 * @param downloadListener
	 * @return
	 */
	public static int serialDlPointFile( String url,
			int DLType, Object args, DownloadListener downloadListener) {
		return serialDl( new DownloadParameter(url, DLType, false), args, downloadListener,
				true);
	}

	/**
	 * 
	 * @param context
	 * @param url
	 * @param DLType
	 */
	public static int serialDlPointFile( String url,
			int dLType, boolean isNewFile, DownloadListener downloadListener) {
		return serialDl(new DownloadParameter(url, dLType, isNewFile), null,
				downloadListener, true);
	}

	/**
	 * 
	 * @param context
	 * @param parameter
	 * @param obj
	 * @param downloadListener
	 * @param isPoint
	 * @return
	 */
	private static int serialDl( DownloadParameter parameter, Object obj,
			DownloadListener downloadListener, boolean isPoint) {
		return SerialDownload.getInstance().start(
				new DownloadPresent( parameter, obj, downloadListener, isPoint));
	}

	/**
	 * Ĭ���������� ,��������
	 * 
	 * @param context
	 * @param url
	 * @param DLType
	 */
	public static int parallelDlFile( String url, int DLType) {
		return parallelDl( new DownloadParameter(url, DLType, false), null, null,
				false);
	}

	/**
	 * Ĭ���������� ,��������
	 * 
	 * @param context
	 * @param url
	 * @param DLType
	 */
	public static int parallelDlFile( String url,
			int DLType, DownloadListener downloadListener) {
		return parallelDl(new DownloadParameter(url, DLType, false), null,
				downloadListener, false);
	}

	public static int parallelDlFile( String url,
			int DLType, Object args, DownloadListener downloadListener) {
		return parallelDl(new DownloadParameter(url, DLType, false), args,
				downloadListener, false);
	}

	public static int parallelDlFile( String url,
			int DLType, boolean isNewFile, DownloadListener downloadListener) {
		return parallelDl( new DownloadParameter(url, DLType, isNewFile), null,
				downloadListener, false);
	}

	/**
	 * Ĭ�϶ϵ����� ,��������
	 * 
	 * @param context
	 * @param url
	 * @param DLType
	 */
	public static int parallelDlPointFile( String url,
			int DLType) {
		return parallelDl( new DownloadParameter(url, DLType, false), null, null,
				true);
	}

	/**
	 * Ĭ�϶ϵ����� ,��������
	 * 
	 * @param context
	 * @param url
	 * @param DLType
	 */
	public static int parallelDlPointFile( String url,
			int DLType, DownloadListener downloadListener) {
		return parallelDl( new DownloadParameter(url, DLType, false), null,
				downloadListener, true);
	}

	public static int parallelDlPointFile( String url,
			int DLType, Object args, DownloadListener downloadListener) {
		return parallelDl( new DownloadParameter(url, DLType, false), args,
				downloadListener, true);
	}

	/**
	 * Ĭ�϶ϵ����� ,��������
	 * 
	 * @param context
	 * @param url
	 * @param DLType
	 */
	public static int parallelDlPointFile( String url,
			int DLType, boolean isNewFile, DownloadListener downloadListener) {
		return parallelDl( new DownloadParameter(url, DLType, isNewFile), null,
				downloadListener, true);
	}

	private static int parallelDl( DownloadParameter parameter,
			Object obj, DownloadListener downloadListener, boolean isPoint) {
		return ParallelDownload.getInstance().start(
				new DownloadPresent( parameter, obj, downloadListener, isPoint));
	}

	/**
	 * ��Ƶ����
	 * 
	 * @param context
	 * @param url
	 * @param DLType
	 */
	public static int videoDlFile( String url, int DLType) {
		return videoDl( new DownloadParameter(url, DLType, false), null, null,
				true);
	}

	/**
	 * ��Ƶ����
	 * 
	 * @param context
	 * @param url
	 * @param DLType
	 */
	public static int videoDlFile( String url, int DLType,
			DownloadListener DLListener) {
		return videoDl( new DownloadParameter(url, DLType, false), null, DLListener,
				true);
	}

	/**
	 * ��Ƶ����
	 * 
	 * @param context
	 * @param url
	 * @param DLType
	 * @param isFileName
	 * @param downloadListener
	 */
	public static int videoDlFile(String url, int DLType,
			boolean isNewFile, DownloadListener downloadListener) {
		return videoDl(new DownloadParameter(url, DLType, isNewFile), null,
				downloadListener, true);
	}

	/**
	 * 
	 * @param context2
	 * @param dlUrl
	 * @param dLType
	 * @param isNewFile
	 * @param DLListener
	 * @param isPoint
	 */
	private static int videoDl( DownloadParameter parameter, Object args,
			DownloadListener DLListener, boolean isPoint) {
		return VideoDownload.getInstance().start(
				new DownloadPresent( parameter, args, DLListener, isPoint));
	}
	
	public static void removeTask(int taskId){
		DownloadManager.removePresent(taskId);
	}

}
